package com.xing.controller;

import com.xing.Utils.Result;
import com.xing.entity.OssEntity;
import com.xing.entity.OssFile;
import com.xing.server.impl.MinioTemplate;
import com.xing.service.OssService;
import com.xing.utils.PageData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.Map;
import java.util.Objects;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2024/4/12 16:27
 */
@Tag(name = "文件管理")
@RestController
@RequestMapping("oss")
public class OssController {
    @Autowired
    private OssService service;

    @Operation(summary = "文件上传")
    @PostMapping("update")
    public Result update(@RequestParam("file") MultipartFile file) {
        Long update = service.update(file);
        return new Result().ok(update.toString());
    }


    @Operation(summary = "根据id获取文件信息")
    @GetMapping("getById")
    public Result getById(@RequestParam Long id) {
        OssEntity ossEntity = service.getById(id);
        return new Result().ok(ossEntity);
    }


    @Operation(summary = "文件列表")
    @GetMapping("page")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result ossEntityPageList(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageData<OssEntity> ossEntityPageData = service.ossEntityPageList(pageNum, pageSize);
        return new Result().ok(ossEntityPageData);
    }


    @Operation(summary = "删除文件")
    @DeleteMapping("delete")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result delete(@RequestParam Long id) {
        return service.delete(id);
    }


}
